//1.手机号验证
$(".telno").blur(checkUsertlno);
function checkUsertlno(){
    //alert("telno");
     var usertelno = $(".telno").val();
     if(usertelno == null || usertelno == ""){
        $(".telno-must").text("手机号码不能为空!");
        return false;
    }else if(!/^[1][3,4,5,7,8][0-9]{9}$/.test(usertelno)){
        $(".telno-must").text("手机号码格式不正确!");
        return false;
    }else{
        $(".telno-must").text("");
        return true;
    }
}

//2.密码验证
$(".psw").blur(checkUserpwd);
function checkUserpwd(){
    var userpwd = $(".psw").val();
    if(userpwd == "" || userpwd == null){
        $(".psw-must").text("密码不能为空!");
        return false;
    }else if(!/^[\w]{6,12}$/.test(userpwd)){
        $(".psw-must").text("密码只能由数字、字母、下划线组成，长度在6-12之间!");
        return false;
    }else{
        $(".psw-must").text("");
        return true;
    }
}

//3.短信验证码验证
$(".check").blur(checkMsg);
function checkMsg() {
    var msg = $(".check").val();
    if (msg == "" || msg == null) {
        $(".check-msg").text("短信验证码不能为空!");
        return false;
    }else{
        $(".check-msg").text("");
        return true;
    }
}

//4单击 “发送验证码”，倒计时 5s
$(".sendMsg").click(setTime);
function setTime() {
    var btn = $(".sendMsg");
    var time = 10;
    btn.disable = true;
    var timer = null;

    timer = setInterval(function () {
        if (time == 0) {
            clearInterval(timer);
            btn.disable = false;
            btn.val("发送短信验证码");
            time = 10;
        } else {
            btn.val(time + "秒后可发送");
            time--;
        }
    }, 1000);

}

//点击注册时验证是否都填写
$(".registBtn").click(function (){
    var usertelno = $(".telno").val();
    if(usertelno == null || usertelno == "") {
        $(".telno-must").text("手机号码不能为空!");
        return false;
    }
    var userpwd = $(".psw").val();
    if(userpwd == "" || userpwd == null){
        $(".psw-must").text("密码不能为空!");
        return false;
    }
    var msg = $(".check").val();
    if (msg == "" || msg == null) {
        $(".check-msg").text("短信验证码不能为空!");
        return false;
    }
    return true;
})